package com.cslg.questionnaires.controller;

import com.cslg.questionnaires.entity.Student;
import com.cslg.questionnaires.entity.Teacher;
import com.cslg.questionnaires.service.CheckFormDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
public class CheckFormDetailsController {
    @Autowired
    private CheckFormDetailsService checkFormDetailsService;

    @GetMapping("/CheckFormDetails/{formId}")
    public ModelAndView getCheckFormDetailsPage(@PathVariable int formId, HttpSession session) {
        String userType = (String) session.getAttribute("userType");
        if (userType.equals("Teacher")) {
            Teacher teacher = (Teacher) session.getAttribute("user");
            int teacherid = teacher.getId();
            HashMap<String, Object> data = checkFormDetailsService.getFormDetailsByFormId(formId, teacherid, userType);
            return new ModelAndView("CheckFormDetails", data);
        } else {
            Student student = (Student) session.getAttribute("user");
            int studentid = student.getId();
            HashMap<String, Object> data = checkFormDetailsService.getFormDetailsByFormId(formId, studentid, userType);
            return new ModelAndView("CheckFormDetails", data);
        }

    }

}
